<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="now" value="<%=new java.util.Date()%>"/>

<div class="row full-width">
	<div class="columns">
		<div
			class="large-12 medium-14 small-16 large-centered medium-centered small-centered columns">
			<!--content-->
			<br>
			<div class="row collapse">
				<div class="large-16 small-16 background-secondary columns">
					<div>
						<br>
						<div class="row">
							<div class="columns" id="subscribe-list">
								<span class="subscribed">YOU HAVE </span>
								<c:choose>
									<c:when test="${fn:length(subscribedFlights) == 0}">
										<span class="subscribed">NOT YET SUBSCRIBED ANY FLIGHT!</span>
									</c:when>
									<c:otherwise>
										<span class="subscribed-number">${fn:length(subscribedFlights)}</span>
										<span class="subscribed-number"> SUBSCRIBED FLIGHT(S)</span>
									</c:otherwise>
								</c:choose>
							</div>
						</div>
						<br>

						<!-- Subscribed flight list -->
						<c:forEach var="subcribedFlight" items="${subscribedFlights}" varStatus="theCount">
							<jsp:useBean id="now" class="java.util.Date"/>
							<fmt:parseDate value="${subcribedFlight.outBoundDate} ${subcribedFlight.outBoundDepartureTime}" var="outBoundDate" pattern="yyyy/MM/dd HH:mm" />
							<c:choose>
								<c:when test="${subcribedFlight.inBoundDepartureTime != null }">
									<fmt:parseDate value="${subcribedFlight.inBoundDate} ${subcribedFlight.inBoundDepartureTime}" var="inBoundDate" pattern="yyyy/MM/dd HH:mm" />								
								</c:when>
								<c:otherwise>
									<fmt:parseDate value="${subcribedFlight.inBoundDate}" var="inBoundDate" pattern="yyyy/MM/dd"/>
								</c:otherwise>
							</c:choose>

							<c:choose>
								<c:when test="${subcribedFlight.typeOfTrip == 'roundTrip'}">
									<c:choose>
										<c:when test="${inBoundDate gt now && subcribedFlight.available == true}">
											<c:set var="out_bound_airline" value="out-bound-airline" />
											<c:set var="in_bound_airline" value="in-bound-airline" />
											<c:set var="green_bold" value="green-bold" />
											<c:set var="navy" value="navy" />
											<c:set var="price" value="price" />
											<c:set var="price_source" value="price-source" />
											<c:set var="ic_flight_depart" value="/resources/img/ic_flight_depart.png"/>
											<c:set var="ic_flight_return" value="/resources/img/ic_flight_return.png"/>
											<c:set var="status" value="Available" />
										</c:when>
										<c:otherwise>
											<c:set var="out_bound_airline" value="unavailable" />
											<c:set var="in_bound_airline" value="unavailable" />
											<c:set var="green_bold" value="unavailable" />
											<c:set var="navy" value="unavailable" />
											<c:set var="price" value="unavailable-price" />
											<c:set var="price_source" value="unavailable-price-source" />
											<c:set var="ic_flight_depart" value="/resources/img/ic_flight_depart_disable.png"/>
											<c:set var="ic_flight_return" value="/resources/img/ic_flight_return_disable.png"/>
											<c:set var="status" value="Unavailable" />
										</c:otherwise>
									</c:choose>
								</c:when>
								<c:otherwise>
									<c:choose>
										<c:when test="${outBoundDate gt now && subcribedFlight.available == true}">
											<c:set var="out_bound_airline" value="out-bound-airline" />
											<c:set var="in_bound_airline" value="in-bound-airline" />
											<c:set var="green_bold" value="green-bold" />
											<c:set var="navy" value="navy" />
											<c:set var="price" value="price" />
											<c:set var="price_source" value="price-source" />
											<c:set var="ic_flight_depart" value="/resources/img/ic_flight_depart.png"/>
											<c:set var="ic_flight_return" value="/resources/img/ic_flight_return.png"/>
											<c:set var="status" value="Available" />
										</c:when>
										<c:otherwise>
											<c:set var="out_bound_airline" value="unavailable" />
											<c:set var="in_bound_airline" value="unavailable" />
											<c:set var="green_bold" value="unavailable" />
											<c:set var="navy" value="unavailable" />
											<c:set var="price" value="unavailable-price" />
											<c:set var="price_source" value="unavailable-price-source" />
											<c:set var="ic_flight_depart" value="/resources/img/ic_flight_depart_disable.png"/>
											<c:set var="ic_flight_return" value="/resources/img/ic_flight_return_disable.png"/>
											<c:set var="status" value="Unavailable" />
										</c:otherwise>
									</c:choose>
								</c:otherwise>
							</c:choose>
							<c:choose>
								<c:when test="${subcribedFlight.classType == 0}">
									<c:set var="classType" value="Economy" />
								</c:when>
								<c:otherwise>
									<c:set var="classType" value="Business" />
								</c:otherwise>
							</c:choose>
							<c:if test=""></c:if>
							<div class="row subscribed-flight" id="flight${theCount.index}">
								<div class="columns">
									<div id="${subcribedFlight.flightId}" class="border-blue notification-center-message-background columns">
										<br>
										<!-- Outbound Info -->
										<div class="large-5 medium-5 small-8 un-padding columns">
											<div class="row collapse">
												<div class="large-1 medium-2 small-2 columns">
													<img src="<c:url value="${ic_flight_depart}"/>" class="flight-icon">
												</div>
												<div class="large-15 medium-14 small-14 columns un-padding">
													<span class="${out_bound_airline}"> ${subcribedFlight.outBoundCarriers} </span> <br>
													<span class="gray">${subcribedFlight.outBoundDate}</span> <br>
													<div style="margin-top: 5px;">
														<span class="${green_bold}">${subcribedFlight.outboundCode}</span>
														<span class="${navy}">${subcribedFlight.outBoundDepartureTime}</span>
														<span class="${green_bold}"> -</span>
														<span class="${green_bold}">${subcribedFlight.inboundCode}</span>
														<span class="${navy}">
															${subcribedFlight.outBoundArrivalTime}&nbsp;
															<c:if test="${subcribedFlight.outBoundDayOver > 0}">
																(+${subcribedFlight.outBoundDayOver})
															</c:if>
														</span> <br>
														<c:choose>
															<c:when test="${subcribedFlight.outBoundNumStops > 0}">
																<span class="${green_bold}">
																	${subcribedFlight.outBoundNumStops} stop(s)&nbsp;${subcribedFlight.outBoundAirportsExpanded}
																</span>
															</c:when>
															<c:otherwise>
																<span class="${green_bold}">Direct</span>
															</c:otherwise>
														</c:choose>
														<span class="${navy}">${subcribedFlight.outBoundDuration}&nbsp;min(s)</span> <br>
														<span class="gray">${classType}</span>
													</div>
													<br>
												</div>
											</div>
										</div>
										<!-- Inbound Info -->
										<div class="large-5 medium-5 small-8 un-padding columns">
											<div class="row collapse">
													<div class="large-1 medium-2 small-2 columns">
														<c:if test="${subcribedFlight.typeOfTrip == 'oneWay'}">
															&nbsp;
														</c:if>
														<c:if test="${subcribedFlight.typeOfTrip == 'roundTrip'}">
															<img src="<c:url value="${ic_flight_return}"/>" class="flight-icon">
														</c:if>
													</div>
													<div class="large-15 medium-14 small-14 columns un-padding">
														<c:if test="${subcribedFlight.typeOfTrip == 'roundTrip'}">
															<span class="${in_bound_airline}"> ${subcribedFlight.inBoundCarriers} </span> <br>
															<span class="gray">${subcribedFlight.inBoundDate}</span> <br>
															<div style="margin-top: 5px;">
																<span class="${green_bold}">${subcribedFlight.inboundCode}</span>
																<span class="${navy}">${subcribedFlight.inBoundDepartureTime}</span>
																<span class="${green_bold}"> -</span>
																<span class="${green_bold}">${subcribedFlight.outboundCode}</span>
																<span class="${navy}">
																	${subcribedFlight.inBoundArrivalTime}&nbsp;
																	<c:if test="${subcribedFlight.inBoundDayOver > 0}">
																		(+${subcribedFlight.inBoundDayOver})
																	</c:if>
																</span> <br>
																<c:choose>
																	<c:when test="${subcribedFlight.inBoundNumStops > 0}">
																		<span class="${green_bold}">
																			${subcribedFlight.inBoundNumStops} stop(s)&nbsp;${subcribedFlight.inBoundAirportsExpanded}
																		</span>
																	</c:when>
																	<c:otherwise>
																		<span class="${green_bold}">Direct</span>
																	</c:otherwise>
																</c:choose>
																<span class="${navy}">${subcribedFlight.inBoundDuration}&nbsp;min(s)</span> <br>
																<span class="gray">${classType}</span>
															</div>
															<br>
														</c:if>
														<c:if test="${subcribedFlight.typeOfTrip == 'oneWay'}">
															<span class="${in_bound_airline}">&nbsp;</span> <br>
															<span class="gray">&nbsp;</span> <br>
															<div style="margin-top: 5px;">
																<span class="${green_bold}">&nbsp;</span>
																<span class="${navy}">&nbsp;</span>
																<span class="${green_bold}">&nbsp;</span>
																<span class="${green_bold}">&nbsp;</span>
																<span class="${navy}">&nbsp;</span> <br>
																<span class="${green_bold}">&nbsp;</span>
																<span class="${navy}">&nbsp;</span> <br>
																<span class="gray">&nbsp;</span>
															</div>
															<br>
														</c:if>
													</div>
											</div>
										</div>
										<!-- Status -->
										<div class="large-3 medium-3 small-8 un-padding columns">
											<div class="columns">
												<span class="${out_bound_airline}">${status}</span> <br> <br>
											</div>
										</div>
										<!-- Price -->
										<div class="large-3 medium-3 small-8 un-padding columns">
											<div class="row">
												<span class="${price}"><font name="vrow">${subcribedFlight.price}</font>
												<input type="hidden" name="realValue" value=${subcribedFlight.price}>
												 <small><font name="vrowCode" id="currencyCode">${subcribedFlight.currencyCode}</font></small>
												 </span>

												<br>
												<span class="price-source"><a target="_blank" href="#" onclick="window.open(getProviderLink('${subcribedFlight.priceProvider}'))">${subcribedFlight.priceProvider}</a></span>
												<br>
												<button class="button unsubscribe right a-subscribe right"
													id="flight${theCount.index}" onclick="requestUnsubsribe('${subcribedFlight.flightId}','${theCount.index}')">
													 <span>
													 	<img src="<c:url value="/resources/img/ic_unsubscribe.png"/>" class="subscribe" />
													 	<span style="bottom: 0px;height: 24px;margin-bottom: 0px;position: absolute;left: 35px;font-size: 16px;">Unsubscribe</span>
													 </span>
												</button>
											</div>
										</div>
									</div>
								</div>
							</div>
							<span id="br${theCount.index}"><br></span>
						</c:forEach>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

